<template>
  <el-dialog title="推广分类" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false" size="700px">
    <el-form size="small" :model="form" ref="form">
      <el-form-item label="分类名称" :label-width="formLabelWidth" prop="tname"
        :rules="[{ required: true, message: '请输入分类名称' }]" style="width: 500px;">
        <el-input v-model="form.tname" placeholder="请输入分类名称"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="addTag()" :disabled="submit_loading">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import NewsApi from '@/api/news.js';
export default {
  data() {
    return {
      form: {
        tname: '',
      },
      /*左边长度*/
      formLabelWidth: '120px',
      /*是否显示*/
      dialogVisible: false,
      /*是否正在提交*/
      submit_loading: false,
    };
  },
  props: ['open_edit', 'form'],
  created() {
    this.dialogVisible = this.open_edit;
  },
  methods: {
    /*添加等级*/
    addTag() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate((valid) => {
        if (valid) {
          self.submit_loading = true;
          NewsApi.type_edit(params, true).then(data => {
            self.submit_loading = false;
            self.$message({
              message: data.msg,
              type: 'success'
            });
            self.dialogFormVisible(true);
          })
            .catch(error => {
              self.submit_loading = false;
            });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit('closeDialog', {
          type: 'success',
          openDialog: false
        })
      } else {
        this.$emit('closeDialog', {
          type: 'error',
          openDialog: false
        })
      }
    }

  }
};
</script>

<style></style>
